{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "s=pd.Series(np.arange(5),np.arange(5)[::-1],dtype=np.int32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4    0\n",
       "3    1\n",
       "2    2\n",
       "1    3\n",
       "0    4\n",
       "dtype: int32"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 我们可以用isin()查看存在的列中符合条件值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4    False\n",
       "3     True\n",
       "2     True\n",
       "1    False\n",
       "0     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.isin(['1','2','4'])#得到索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    1\n",
       "2    2\n",
       "0    4\n",
       "dtype: int32"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[s.isin(['1','2','4'])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 多重索引isin()的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 必须按照columns进行，他自动会帮我们计算2*3序列\n",
    "s2=pd.Series(np.arange(6),index=pd.MultiIndex.from_product([[1,2],['a','b','c']]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1  a    0\n",
       "   b    1\n",
       "   c    2\n",
       "2  a    3\n",
       "   b    4\n",
       "   c    5\n",
       "dtype: int32"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1  a    0\n",
       "2  c    5\n",
       "dtype: int32"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.iloc[s2.index.isin([(1,'a'),(2,'c')])]#二维索引操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2  a    3\n",
       "   b    4\n",
       "   c    5\n",
       "dtype: int32"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2[s2>2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 我们可以构件时间序列为索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dates=pd.date_range(start=\"20171112\",periods=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df=pd.DataFrame(np.random.randn(8,4),index=dates,columns=['A','B','C','D'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-11-12</th>\n",
       "      <td>0.884522</td>\n",
       "      <td>-0.653455</td>\n",
       "      <td>-0.815459</td>\n",
       "      <td>0.327165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-13</th>\n",
       "      <td>1.562581</td>\n",
       "      <td>-0.173401</td>\n",
       "      <td>-1.324482</td>\n",
       "      <td>0.468172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-14</th>\n",
       "      <td>0.399191</td>\n",
       "      <td>0.391059</td>\n",
       "      <td>-0.334431</td>\n",
       "      <td>-2.405515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-15</th>\n",
       "      <td>-0.497012</td>\n",
       "      <td>1.248537</td>\n",
       "      <td>-1.632952</td>\n",
       "      <td>2.551556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-16</th>\n",
       "      <td>-0.096779</td>\n",
       "      <td>0.050090</td>\n",
       "      <td>0.071545</td>\n",
       "      <td>1.699678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-17</th>\n",
       "      <td>-0.170767</td>\n",
       "      <td>-0.464986</td>\n",
       "      <td>0.968528</td>\n",
       "      <td>-0.410740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-18</th>\n",
       "      <td>1.233395</td>\n",
       "      <td>-0.362247</td>\n",
       "      <td>2.867107</td>\n",
       "      <td>-0.204222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-19</th>\n",
       "      <td>0.289176</td>\n",
       "      <td>-0.638503</td>\n",
       "      <td>-0.120374</td>\n",
       "      <td>0.666057</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2017-11-12  0.884522 -0.653455 -0.815459  0.327165\n",
       "2017-11-13  1.562581 -0.173401 -1.324482  0.468172\n",
       "2017-11-14  0.399191  0.391059 -0.334431 -2.405515\n",
       "2017-11-15 -0.497012  1.248537 -1.632952  2.551556\n",
       "2017-11-16 -0.096779  0.050090  0.071545  1.699678\n",
       "2017-11-17 -0.170767 -0.464986  0.968528 -0.410740\n",
       "2017-11-18  1.233395 -0.362247  2.867107 -0.204222\n",
       "2017-11-19  0.289176 -0.638503 -0.120374  0.666057"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 查询方式 (三种)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-11-12</th>\n",
       "      <td>0.884522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-13</th>\n",
       "      <td>1.562581</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-14</th>\n",
       "      <td>0.399191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-15</th>\n",
       "      <td>-0.497012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-16</th>\n",
       "      <td>-0.096779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-17</th>\n",
       "      <td>-0.170767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-18</th>\n",
       "      <td>1.233395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-19</th>\n",
       "      <td>0.289176</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A\n",
       "2017-11-12  0.884522\n",
       "2017-11-13  1.562581\n",
       "2017-11-14  0.399191\n",
       "2017-11-15 -0.497012\n",
       "2017-11-16 -0.096779\n",
       "2017-11-17 -0.170767\n",
       "2017-11-18  1.233395\n",
       "2017-11-19  0.289176"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select(lambda x:x=='A',axis='columns') #λ表达式，一般很少用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-11-12</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.653455</td>\n",
       "      <td>-0.815459</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-13</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.173401</td>\n",
       "      <td>-1.324482</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-14</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.334431</td>\n",
       "      <td>-2.405515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-15</th>\n",
       "      <td>-0.497012</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.632952</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-16</th>\n",
       "      <td>-0.096779</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-17</th>\n",
       "      <td>-0.170767</td>\n",
       "      <td>-0.464986</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.410740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-18</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.362247</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.204222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-19</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.638503</td>\n",
       "      <td>-0.120374</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2017-11-12       NaN -0.653455 -0.815459       NaN\n",
       "2017-11-13       NaN -0.173401 -1.324482       NaN\n",
       "2017-11-14       NaN       NaN -0.334431 -2.405515\n",
       "2017-11-15 -0.497012       NaN -1.632952       NaN\n",
       "2017-11-16 -0.096779       NaN       NaN       NaN\n",
       "2017-11-17 -0.170767 -0.464986       NaN -0.410740\n",
       "2017-11-18       NaN -0.362247       NaN -0.204222\n",
       "2017-11-19       NaN -0.638503 -0.120374       NaN"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.where(df<0) #这样操作很不好 替换NAN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-11-12</th>\n",
       "      <td>*</td>\n",
       "      <td>-0.653455</td>\n",
       "      <td>-0.815459</td>\n",
       "      <td>*</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-13</th>\n",
       "      <td>*</td>\n",
       "      <td>-0.173401</td>\n",
       "      <td>-1.32448</td>\n",
       "      <td>*</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-14</th>\n",
       "      <td>*</td>\n",
       "      <td>*</td>\n",
       "      <td>-0.334431</td>\n",
       "      <td>-2.40552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-15</th>\n",
       "      <td>-0.497012</td>\n",
       "      <td>*</td>\n",
       "      <td>-1.63295</td>\n",
       "      <td>*</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-16</th>\n",
       "      <td>-0.0967786</td>\n",
       "      <td>*</td>\n",
       "      <td>*</td>\n",
       "      <td>*</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-17</th>\n",
       "      <td>-0.170767</td>\n",
       "      <td>-0.464986</td>\n",
       "      <td>*</td>\n",
       "      <td>-0.41074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-18</th>\n",
       "      <td>*</td>\n",
       "      <td>-0.362247</td>\n",
       "      <td>*</td>\n",
       "      <td>-0.204222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-11-19</th>\n",
       "      <td>*</td>\n",
       "      <td>-0.638503</td>\n",
       "      <td>-0.120374</td>\n",
       "      <td>*</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    A         B         C         D\n",
       "2017-11-12          * -0.653455 -0.815459         *\n",
       "2017-11-13          * -0.173401  -1.32448         *\n",
       "2017-11-14          *         * -0.334431  -2.40552\n",
       "2017-11-15  -0.497012         *  -1.63295         *\n",
       "2017-11-16 -0.0967786         *         *         *\n",
       "2017-11-17  -0.170767 -0.464986         *  -0.41074\n",
       "2017-11-18          * -0.362247         * -0.204222\n",
       "2017-11-19          * -0.638503 -0.120374         *"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.where(df<0,'*') #否则我们可以执行“*”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.500346</td>\n",
       "      <td>0.768935</td>\n",
       "      <td>0.619841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.161103</td>\n",
       "      <td>0.406865</td>\n",
       "      <td>0.978126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.874814</td>\n",
       "      <td>0.923701</td>\n",
       "      <td>0.016023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.244073</td>\n",
       "      <td>0.840637</td>\n",
       "      <td>0.638146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.097223</td>\n",
       "      <td>0.083490</td>\n",
       "      <td>0.918172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.492369</td>\n",
       "      <td>0.409309</td>\n",
       "      <td>0.196101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.031570</td>\n",
       "      <td>0.825770</td>\n",
       "      <td>0.033123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.094824</td>\n",
       "      <td>0.026568</td>\n",
       "      <td>0.521921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.023791</td>\n",
       "      <td>0.194310</td>\n",
       "      <td>0.215923</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.876946</td>\n",
       "      <td>0.503194</td>\n",
       "      <td>0.398730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c\n",
       "0  0.500346  0.768935  0.619841\n",
       "1  0.161103  0.406865  0.978126\n",
       "2  0.874814  0.923701  0.016023\n",
       "3  0.244073  0.840637  0.638146\n",
       "4  0.097223  0.083490  0.918172\n",
       "5  0.492369  0.409309  0.196101\n",
       "6  0.031570  0.825770  0.033123\n",
       "7  0.094824  0.026568  0.521921\n",
       "8  0.023791  0.194310  0.215923\n",
       "9  0.876946  0.503194  0.398730"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.rand(10,3),columns = list('abc'))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.492369</td>\n",
       "      <td>0.409309</td>\n",
       "      <td>0.196101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.876946</td>\n",
       "      <td>0.503194</td>\n",
       "      <td>0.398730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c\n",
       "5  0.492369  0.409309  0.196101\n",
       "9  0.876946  0.503194  0.398730"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query('a>=b and b>c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.500346</td>\n",
       "      <td>0.768935</td>\n",
       "      <td>0.619841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.874814</td>\n",
       "      <td>0.923701</td>\n",
       "      <td>0.016023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.244073</td>\n",
       "      <td>0.840637</td>\n",
       "      <td>0.638146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.097223</td>\n",
       "      <td>0.083490</td>\n",
       "      <td>0.918172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.492369</td>\n",
       "      <td>0.409309</td>\n",
       "      <td>0.196101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.031570</td>\n",
       "      <td>0.825770</td>\n",
       "      <td>0.033123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.094824</td>\n",
       "      <td>0.026568</td>\n",
       "      <td>0.521921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.876946</td>\n",
       "      <td>0.503194</td>\n",
       "      <td>0.398730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c\n",
       "0  0.500346  0.768935  0.619841\n",
       "2  0.874814  0.923701  0.016023\n",
       "3  0.244073  0.840637  0.638146\n",
       "4  0.097223  0.083490  0.918172\n",
       "5  0.492369  0.409309  0.196101\n",
       "6  0.031570  0.825770  0.033123\n",
       "7  0.094824  0.026568  0.521921\n",
       "9  0.876946  0.503194  0.398730"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query('a>=b or b>c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.492369</td>\n",
       "      <td>0.409309</td>\n",
       "      <td>0.196101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.876946</td>\n",
       "      <td>0.503194</td>\n",
       "      <td>0.398730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c\n",
       "5  0.492369  0.409309  0.196101\n",
       "9  0.876946  0.503194  0.398730"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query('a>=b & b>c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.500346</td>\n",
       "      <td>0.768935</td>\n",
       "      <td>0.619841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.874814</td>\n",
       "      <td>0.923701</td>\n",
       "      <td>0.016023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.244073</td>\n",
       "      <td>0.840637</td>\n",
       "      <td>0.638146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.097223</td>\n",
       "      <td>0.083490</td>\n",
       "      <td>0.918172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.492369</td>\n",
       "      <td>0.409309</td>\n",
       "      <td>0.196101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.031570</td>\n",
       "      <td>0.825770</td>\n",
       "      <td>0.033123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.094824</td>\n",
       "      <td>0.026568</td>\n",
       "      <td>0.521921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.876946</td>\n",
       "      <td>0.503194</td>\n",
       "      <td>0.398730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c\n",
       "0  0.500346  0.768935  0.619841\n",
       "2  0.874814  0.923701  0.016023\n",
       "3  0.244073  0.840637  0.638146\n",
       "4  0.097223  0.083490  0.918172\n",
       "5  0.492369  0.409309  0.196101\n",
       "6  0.031570  0.825770  0.033123\n",
       "7  0.094824  0.026568  0.521921\n",
       "9  0.876946  0.503194  0.398730"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query('a>=b | b>c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
